package judlawei.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;

public class Submeter extends JPanel {

    private JButton adicionarArquivo;
    private JTextField campoNomeArquivo;
    private JLabel nomeArquivo;

    public Submeter() {

        
        initComponents();
        construirLayout();
        inicializarListeners();

    }

    private void initComponents(){
        campoNomeArquivo = new JTextField();
        adicionarArquivo = new JButton();
        nomeArquivo = new JLabel();

        campoNomeArquivo.setText("insirir arquivo");
        adicionarArquivo.setText("Adicionar");
        nomeArquivo.setText("Nome do Arquivo");
    }
    
    private void construirLayout() {
        GroupLayout submeterLayout = new GroupLayout(this);
        this.setLayout(submeterLayout);
        submeterLayout
                .setHorizontalGroup(submeterLayout
                        .createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addGroup(
                                GroupLayout.Alignment.TRAILING,
                                submeterLayout
                                        .createSequentialGroup()
                                        .addContainerGap(68, Short.MAX_VALUE)
                                        .addGroup(
                                                submeterLayout
                                                        .createParallelGroup(
                                                                GroupLayout.Alignment.LEADING)
                                                        .addComponent(
                                                                nomeArquivo)
                                                        .addGroup(
                                                                submeterLayout
                                                                        .createSequentialGroup()
                                                                        .addComponent(
                                                                                campoNomeArquivo,
                                                                                GroupLayout.PREFERRED_SIZE,
                                                                                342,
                                                                                GroupLayout.PREFERRED_SIZE)
                                                                        .addPreferredGap(
                                                                                LayoutStyle.ComponentPlacement.RELATED)
                                                                        .addComponent(
                                                                                adicionarArquivo)))
                                        .addGap(47, 47, 47)));
        submeterLayout
                .setVerticalGroup(submeterLayout
                        .createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addGroup(
                                submeterLayout
                                        .createSequentialGroup()
                                        .addContainerGap()
                                        .addComponent(nomeArquivo,
                                                GroupLayout.PREFERRED_SIZE, 14,
                                                GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(
                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(
                                                submeterLayout
                                                        .createParallelGroup(
                                                                GroupLayout.Alignment.BASELINE)
                                                        .addComponent(
                                                                campoNomeArquivo,
                                                                GroupLayout.PREFERRED_SIZE,
                                                                GroupLayout.DEFAULT_SIZE,
                                                                GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(
                                                                adicionarArquivo))
                                        .addContainerGap(76, Short.MAX_VALUE)));
    }

    private void inicializarListeners() {

        campoNomeArquivo.addFocusListener(new FocusListener() {

            @Override
            public void focusLost(FocusEvent e) {
                // TODO Auto-generated method stub

                if (campoNomeArquivo.getText() == "")
                    campoNomeArquivo.setText("inserir arquivo");
            }

            @Override
            public void focusGained(FocusEvent e) {
                // TODO Auto-generated method stub
                campoNomeArquivo.setText("");
            }
        });

        adicionarArquivo.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                System.out.println(campoNomeArquivo.getText());
            }
        });

    }

}
